<template>
  <div class="app-container">
    <div style="margin-bottom: 10px">
      <span>招中标数据查询</span>
    </div>
    <el-form
      ref="formData"
      size="small"
      :model="formData1"
      :rules="rules"
      :inline="true"
      class="demo-form-inline"
      style="margin-left: 20px;"
      label-width="100px"
    >
      <el-row>
        <el-col :span="5">
          <el-form-item label="来源:" prop="author">
            <el-input
              v-model="formData1.author"
              placeholder="请输入来源"
              clearable
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="地区id:" prop="areaId">
            <el-select
              v-model="formData1.areaId"
              filterable
              placeholder="请选择地区id"
              style="width: 200px"
            >
              <el-option
                v-for="item in cities"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="查询条数:" prop="limit">
            <el-input-number
              v-model="formData1.limit"
              placeholder="请输入来源"
              clearable
              :min="1"
              :step="10"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="5">
          <el-form-item label="表名:" prop="info">
            <el-select
              v-model="formData1.tableName"
              filterable
              placeholder="请选择表名"
              style="width: 200px"
            >
              <el-option label="stang_bid_new" value="stang_bid_new" />
              <el-option label="stang_cbid" value="stang_cbid" />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="发布时间:" prop="pubtime">
            <el-date-picker
              v-model="formData1.pubtime"
              type="date"
              placeholder="选择发布时间"
              style="width: 200px"
              value-format="yyyy-MM-dd"
            />
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-form-item label="入库时间:" prop="addTime">
            <el-date-picker
              v-model="formData1.addTime"
              type="datetime"
              placeholder="选择入库时间"
              style="width: 200px"
              value-format="yyyy-MM-dd HH:mm:ss"
            />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="6">
          <el-form-item label="info是否为空:" prop="author" label-width="100px">
            <el-radio v-model="formData1.info" label="true">是</el-radio>
            <el-radio v-model="formData1.info" label="false">否</el-radio>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="1">
          <el-button ref="init1" type="primary" size="mini" @click="init1">生成</el-button>
        </el-col>
        <el-col :span="1">
          <el-button ref="reset1" type="primary" size="mini" @click="reset1">重置</el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <el-col :span="12">
        <el-input
          v-model="sql1"
          type="textarea"
          :rows="15"
          placeholder="sql语句"
          style="margin-left: 20px; margin-top: 10px"
        />
      </el-col>
    </el-row>

  </div>
</template>

<script>
export default {
  name: 'Sql',
  data() {
    return {
      formData1: {
        pubtime: '',
        areaId: '',
        author: '',
        info: 'false',
        addTime: '',
        limit: 100,
        tableName: 'stang_bid_new'
      },
      sql1: '',
      cities: [
        {
          value: 1,
          label: '中国'
        }, {
          value: 2,
          label: '北京'
        }, {
          value: 3,
          label: '安徽'
        }, {
          value: 4,
          label: '福建'
        }, {
          value: 5,
          label: '甘肃'
        }, {
          value: 6,
          label: '广东'
        }, {
          value: 7,
          label: '广西'
        }, {
          value: 8,
          label: '贵州'
        }, {
          value: 9,
          label: '海南'
        }, {
          value: 10,
          label: '河北'
        }, {
          value: 11,
          label: '河南'
        }, {
          value: 12,
          label: '黑龙江'
        }, {
          value: 13,
          label: '湖北'
        }, {
          value: 14,
          label: '湖南'
        }, {
          value: 15,
          label: '吉林'
        }, {
          value: 16,
          label: '江苏'
        }, {
          value: 17,
          label: '江西'
        }, {
          value: 18,
          label: '辽宁'
        }, {
          value: 19,
          label: '内蒙古'
        }, {
          value: 20,
          label: '宁夏'
        }, {
          value: 21,
          label: '青海'
        }, {
          value: 22,
          label: '山东'
        }, {
          value: 23,
          label: '山西'
        }, {
          value: 24,
          label: '陕西'
        }, {
          value: 25,
          label: '上海'
        }, {
          value: 26,
          label: '四川'
        }, {
          value: 27,
          label: '天津'
        }, {
          value: 28,
          label: '西藏'
        }, {
          value: 29,
          label: '新疆'
        }, {
          value: 30,
          label: '云南'
        }, {
          value: 31,
          label: '浙江'
        }, {
          value: 32,
          label: '重庆'
        }, {
          value: 33,
          label: '香港'
        }, {
          value: 34,
          label: '台湾'
        }, {
          value: 35,
          label: '澳门'
        }
      ],
      cateIds: [
        {
          value: 1,
          label: '招标'
        },
        {
          value: 2,
          label: '中标'
        },
        {
          value: 3,
          label: '开标记录'
        },
        {
          value: 4,
          label: '答疑补遗澄清变更'
        },
        {
          value: 5,
          label: '中标变更'
        },
        {
          value: 6,
          label: '废标流标终止'
        },
        {
          value: 7,
          label: '资格预审结果'
        },
        {
          value: -1,
          label: '未分类别'
        }
      ],
      rules: {

      }
    }
  },

  created() {
    const date = new Date()
    const pubtime = date.getFullYear() + '-' + (date.getMonth() + 1).toString().padStart(2, '0') + '-' + date.getDate()
    this.formData1.pubtime = pubtime
  },

  methods: {
    init1() {
      let sql1 = 'SELECT id, area_id, cate_id, title, author, pubtime, intro, info, outurl, add_time\n' +
        'FROM `' + this.formData1.tableName + '` \n' +
        'where area_id = ' + this.formData1.areaId + ' and author = "' + this.formData1.author + '"'
      if (this.formData1.pubtime) {
        sql1 = sql1 + ' and pubtime = "' + this.formData1.pubtime + '"'
      }
      if (this.formData1.info === 'true') {
        sql1 = sql1 + ' and info = "" '
      }
      if (this.formData1.addTime) {
        const timeStamp = new Date(this.formData1.addTime).getTime() / 1000
        sql1 = sql1 + ' and add_time >= ' + timeStamp
      }
      sql1 = sql1 + ' \norder by add_time desc limit 0, ' + this.formData1.limit
      this.sql1 = sql1
      this.$nextTick(() => {
        this.$refs.init1.$el.blur()
      })
    },

    reset1() {
      const date = new Date()
      const pubtime = date.getFullYear() + '-' + (date.getMonth() + 1).toString().padStart(2, '0') + '-' + date.getDate()
      this.formData1 = {
        pubtime: pubtime,
        areaId: '',
        author: '',
        info: 'false',
        addTime: '',
        limit: 100,
        tableName: 'stang_bid_new'
      }
      this.sql1 = ''
      this.$nextTick(() => {
        this.$refs.reset1.$el.blur()
      })
    }
  }
}
</script>

<style scoped>

</style>
<style>

</style>
